class Watcher {
    constructor(vm, expr, cb) {
        this.vm = vm;
        this.expr = expr;
        this.cb = cb;
        this.oldVal = this.getData()
    }

    update() {
        let newVal=this.getData()
        if (newVal!==this.oldVal) {
            this.cb(newVal)
            this.oldVal=newVal
        }
    }

    getData() {
        let resolved = this.vm.$data
        this.expr.split('.').forEach(key => resolved = resolved[key])
        return resolved
    }

}
